<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Vue中操作数组</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <button @click="test1">修改张三的名字</button>
      <button @click="test2">修改张三的年龄</button>
      <button @click="test3">修改张三</button>
      <ul>
        <li v-for="p in persons" :key="p.id">
          {{p.name}} - {{p.age}}
        </li>
      </ul>
    </div>

    <script type="text/javascript">
      const vm = new Vue({
        el:'#demo',
        data:{
          a:1,
          b:2,
          c:{
            d:{
              e:{
                f:3
              }
            }
          },
          persons:[
            {id:'76r76ewqd1',name:'张三',age:18},
            {id:'76r76ewqd2',name:'李四',age:19},
            {id:'76r76ewqd3',name:'王五',age:20}
          ]
        },
        methods:{
          test1(){
            this.persons[0].name = 'zhang-san'
          },
          test2(){
            this.persons[0].age += 1
          },
          test3(){
            // this.persons[0] = {id:'76r76ewqd4',name:'马老师',age:60}
            this.persons.splice(0,1,{id:'76r76ewqd4',name:'马老师',age:60})
            console.log(this.persons.splice === Array.prototype.splice)
          },
        }
      })
      console.log(vm)
    </script>
  </body>
</html>